<?php
/**
 * 公共事务
 * Enter description here ...
 * @author cc
 *
 */
namespace Home\Controller;
use Think\Controller;
class CircularController extends CommonController{
	public function way(){
		session("action","Circular");
		session("menu_id",I('get.menu_id',0,'intval'));
		$this->redirect("Public/index");
	}
	
	public function index(){
		$circular = M("circular");
		$dept = M("sys_dept");
		$data_dept = $dept->select();
		
		$count = $circular->count();
		$page = new \Think\Page($count,C("PAGE_LIST_ROWS"));
		$show = $page->show();
		$data = $circular->order('create_time desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('data_dept',$data_dept);
		$this->assign('data',$data);
		$this->assign("page",$show);
		$this->assign("empty", emptyhtml("list"));
		$this->display();
	}
	
	public function lists(){
		$circular = M("circular");
		$dept = M("sys_dept");
		$data_dept = $dept->select();
		
		$count = $circular->count();
		$page = new \Think\Page($count,C("PAGE_LIST_ROWS"));
		$show = $page->show();
		$data = $circular->order('create_time desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('data_dept',$data_dept);
		$this->assign('data',$data);
		$this->assign("page",$show);
		$this->assign("empty", emptyhtml("list"));
		$this->display();
	}
	
	public function add(){
		$this->display();
	}
	
	public function insert(){
		if(!IS_POST){$this->error("非法表单"); exit;}
		$data = $_POST;
		$data['author'] = session("name");
		$data['create_time'] = date("Y-m-d H:i:s");
		$circular = D("Circular");
		if(!$circular->create()){
			$this->error($circular->getError());
		}else{
			$success = $circular->data($data)->add();
			if($success){
				$this->systemlog("add","公告通知管理", "添加公告通知---".$data['title']);
				$this->success("添加公告通知成功！","lists");
			}else{
				$this->success("添加公告通知失败！");
			}
		}
	}
	
	public function edit(){
		$id = I('get.id');
		if(!is_id($id)){ $this->error("非法参数！"); }
		$circular = M("circular");
		$data = $circular->where("id=%d",$id)->find();
		$this->assign("data", $data);
		$this->display();
	}
	
	public function save(){
		if(!IS_POST){$this->error("非法表单"); exit;}
		$id = I('post.id');
		if(!is_id($id)){ $this->error("非法参数！"); }
		$data = $_POST;
		$circular = D("Circular");
		if(!$circular->create()){
			$this->error($circular->getError());
		}else{
			$success = $circular->where("id=%d",$id)->data($data)->save();
			if($success){
				$this->systemlog("edit","公告通知管理", "修改公告通知---".$data['title']);
				$this->success("修改公告通知成功！",'lists');
			}else{
				$this->success("修改公告通知失败！");
			}
		}
	}
	
	public function delete(){
		$id = I('get.id');
		if(!is_id($id)){ $this->error("非法参数！"); }
		$circular = M("circular");
		$title = $circular->where("id=%d",$id)->getField("title");
		$success = $circular->where("id=%d",$id)->delete();
		if($success){
			$this->systemlog("delete","公告通知管理", "删除公告通知---".$title);
			$this->success("删除公告通知成功！","lists");
		}else{
			$this->success("删除公告通知失败！");
		}
	}
	
	public function view(){
		$id = I('get.id');
		if(!is_id($id)){ $this->error("非法参数！"); }
		$circular = M("circular");
		$data = $circular->where("id=%d",$id)->find();
		$this->assign("data", $data);
		$this->display();
	}
    
    public function _empty($name){
    	$this->emptyaction($name);
    }
}
?>